﻿/// ****************************************************************************
/// Author:	        Robin Zhu
/// Create Date:	2012-4-16
/// Purpose: 		用户标识类
/// ****************************************************************************
/// Modify By		Date			Remark
/// ****************************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;
using System.Runtime.InteropServices;
using System.Runtime.Caching;

namespace RB.Web.Security
{
    [SerializableAttribute]
    [ComVisibleAttribute(true)]
    public class VarIdentity : MarshalByRefObject, IIdentity
    {
        public VarIdentity(UserSession userSession)
        {
            _userSession = userSession;
        }

        public VarIdentity()
        {
            // TODO: Complete member initialization
        }

        private UserSession _userSession = null;

        public string Ticket
        {
            get { return _userSession != null ? _userSession.Ticket : ""; }
        }

        public Guid UserId
        {
            get { return _userSession != null ? _userSession.UserId : Guid.Empty; }
        }

        public bool IsStaff
        {
            get { return _userSession != null ? _userSession.IsStaff : false; }
        }

        public string[] PermissionCodes
        {
            get { return _userSession != null ? _userSession.PermissionCodes : new string[0]; }
        }

        public string NickName
        {
            get { return _userSession != null ? _userSession.NickName : string.Empty; }
        }

        #region IIdentity属性

        public string AuthenticationType
        {
            get { return "Var"; }
        }

        public bool IsAuthenticated
        {
            get { return true; }
        }

        public string Name
        {
            get { return _userSession != null ? _userSession.UserName : ""; }
        }

        public IDictionary<string, object> Cache
        {
            get
            {
                return UserCacheManager.Get(Ticket);
            }
        }

        #endregion IIdentity属性
    }
}
